package com.hfuuTaf.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hfuuTaf.mapper.registerMapper;
import com.hfuuTaf.pojo.register;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.Objects;

@RestController
public class safeRestController {
    private final registerMapper registerMapper;

    public safeRestController(com.hfuuTaf.mapper.registerMapper registerMapper) {
        this.registerMapper = registerMapper;
    }


    @PostMapping("/post/addClubMember")
    public boolean Verify(HttpSession session,
                          @RequestParam("username") String username,
                          @RequestParam("password") String password
    ) {
        session.setAttribute("userLoginInfo",username);
        if (Objects.equals(username, "hfuutaf") && Objects.equals(password, "dzr666")) {
            return true;
        }
        return false;

    }
    @PostMapping("/post/close")
    public void closeVerify(HttpSession session
    ) {
        session.setAttribute("userLoginInfo",null);
    }

    /**
     * 确认
     */
    @PostMapping("/index/post/detail")
    public boolean confirm(@RequestParam(value = "id") int id) {
        QueryWrapper<register> wrapper = new QueryWrapper<>();
        wrapper.eq("id", id);
        register register = new register();
        register.setConfirm(1);
        registerMapper.update(register, wrapper);
        return true;
    }

    /**
     * 删除
     */
    @GetMapping("/register/get/delete")
    public boolean delete(@RequestParam(value = "id") int id) {
        registerMapper.deleteById(id);
        return true;
    }
}
